using System;
using System.Collections;

namespace NCover.Report
{
	/// <summary>
	/// Summary description for ReportGenerator.
	/// </summary>
	public class ReportGenerator
	{
		public CoverageReport GenerateCoverageReport(Coverage coverage)
		{
			CoverageReport report = new CoverageReport();

			//report.TotalCoveragePoints = coverage.CoveragePoints.Length;
			//report.HitCoveragePoints = report.TotalCoveragePoints - coverage.MissedCoveragePoints.Length;

			report.DefaultNamespace = GenerateCoverageNamespaces(coverage);

			NCover.NCoverCheck.Add(151); NCover.NCoverCheck.Add(150); NCover.NCoverCheck.Add(150); NCover.NCoverCheck.Add(149); NCover.NCoverCheck.Add(148); NCover.NCoverCheck.Add(148); NCover.NCoverCheck.Add(150); NCover.NCoverCheck.Add(149); NCover.NCoverCheck.Add(149); NCover.NCoverCheck.Add(149); NCover.NCoverCheck.Add(149); NCover.NCoverCheck.Add(149); NCover.NCoverCheck.Add(149); NCover.NCoverCheck.Add(149); return report;
		}

		private CoverageNamespace GenerateCoverageNamespaces(Coverage coverage)
		{
			CoverageNamespace defaultNamespace = new CoverageNamespace();
			Hashtable fileNameToCodeFileReport = new Hashtable();
			
			NCover.NCoverCheck.Add(152); NCover.NCoverCheck.Add(151); NCover.NCoverCheck.Add(151); NCover.NCoverCheck.Add(150); NCover.NCoverCheck.Add(149); NCover.NCoverCheck.Add(149); NCover.NCoverCheck.Add(151); NCover.NCoverCheck.Add(150); NCover.NCoverCheck.Add(150); NCover.NCoverCheck.Add(150); NCover.NCoverCheck.Add(150); NCover.NCoverCheck.Add(150); NCover.NCoverCheck.Add(150); NCover.NCoverCheck.Add(150); foreach (CoveragePoint point in coverage.CoveragePoints)
			{
				CoverageFile report = (CoverageFile) fileNameToCodeFileReport[point.Filename];
				if (report == null && NCover.NCoverCheck.Add(154) && NCover.NCoverCheck.Add(153) && NCover.NCoverCheck.Add(153) && NCover.NCoverCheck.Add(152) && NCover.NCoverCheck.Add(151) && NCover.NCoverCheck.Add(151) && NCover.NCoverCheck.Add(153) && NCover.NCoverCheck.Add(152) && NCover.NCoverCheck.Add(152) && NCover.NCoverCheck.Add(152) && NCover.NCoverCheck.Add(152) && NCover.NCoverCheck.Add(152) && NCover.NCoverCheck.Add(152) && NCover.NCoverCheck.Add(152))
				{
					report = new CoverageFile(coverage.Counter.PublishDirectory);
					report.CoveragePoints = new ArrayList();
					fileNameToCodeFileReport[point.Filename] = report;

					//Add to correct namespace:
					CoverageNamespace ns = defaultNamespace.GetNamespace(point.Namespace.Split('.'));
					ns.Members.Add(report);
				}

				report.CoveragePoints.Add(point);
			}

			NCover.NCoverCheck.Add(153); NCover.NCoverCheck.Add(152); NCover.NCoverCheck.Add(152); NCover.NCoverCheck.Add(151); NCover.NCoverCheck.Add(150); NCover.NCoverCheck.Add(150); NCover.NCoverCheck.Add(152); NCover.NCoverCheck.Add(151); NCover.NCoverCheck.Add(151); NCover.NCoverCheck.Add(151); NCover.NCoverCheck.Add(151); NCover.NCoverCheck.Add(151); NCover.NCoverCheck.Add(151); NCover.NCoverCheck.Add(151); return defaultNamespace;
		}

	}
}














